<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/8/2 0002
 * Time: 15:48
 */

namespace app\api\controller;

use app\service\BizproService;
use app\service\MemberService;
use base\Excel;
use think\Db;

/**
 * 商品
 * @author   juzi
 * @blog    https://blog.csdn.net/juziaixiao
 * @version  0.0.1
 * @datetime 2020年7月22日10:57:35
 */
class Bizpro extends Common
{


    /**
     * [__construct 构造方法]
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月22日10:57:35
     */
    public function __construct()
    {
        // 调用父类前置方法
        parent::__construct();
    }

    /**
     * [Index 商品列表]
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月22日10:57:35
     */
    public function Index()
    {

        $params = $this->data_post;
        $where = BizproService::BizListWhere($params);
        $data_params = [
            'where' => $where,
            'page' =>isset($params['is_page'])?$params['is_page']:false,
            'field' => 'b.id b_id,b.name b_name,sd.standard_desc,b.label,b.imgurl,b.old_price,b.fake_num,b.real_num',
            'order_by'=>$params['order']=='fake_num'?'b.fake_num':'b.sale_price',
            'sort'=>$params['mark']=='desc'?'desc':'asc',
            'rand'=>isset($params['rand'])?$params['rand']:false,
            'number'=>20
        ];

//        if(!isset($params['keywords']))
//        {
//            $data_params['m'] = 0;
//            $data_params['n'] = 20;
//        }

        $re =BizproService::BizproList($data_params);

        $re['data'] = array_values($re['data']);
        $data = empty($re['data'][0]) ? [] : $re['data'];
        return json(array('status'=>true,'msg'=>'获取成功','code'=>0,'data'=>$data,'page'=>$re['page']));



    }

    /**
     * [Detail 商品详情]
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月22日10:57:35
     */
    public function Detail()
    {
        $params = $this->data_get;
        $where=[
            'b.id'=>$params['id']
        ];
        $data_params = [
            'where' => $where,
            'page' => false,
            'field' => 'b.bizpro_number,b.supplier_id,b.detail,b.fake_num,b.old_price,b.id b_id,b.name b_name,b.label,b.imgurl,b.old_price,b.banner,b.standard_base,sd.standard_desc,b.express_price',
        ];
        $re =BizproService::BizproList($data_params);
        MemberService::SaveLogBrowse(['member_id'=>$this->member_id,'bizpro_id'=>$params['id']]);
        $data = empty($re['data'][0]) ? [] : $re['data'];
        return DataReturn('获取成功',0,$data);
    }
    /**
     * [StandardBase 商品规格]
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月22日10:57:35
     */
    public function StandardBase()
    {
        $params = $this->data_get;
        $where = [
            'b.id'=>$params['id']
        ];
        $data_params = [
            'where' => $where,
            'page' => false,
            'field' => 'b.standard_base',
            'm'=>0,
            'n'=>1
        ];
        $re = BizproService::BizproList($data_params);
        $data = empty($re['data'][0]) ? [] : $re['data'];
        return DataReturn('获取成功',0,$data);
    }

    /**
     * [StandardPrice 根据规格查询价位]
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月22日10:57:35
     */
    public function StandardPrice()
    {
        $params = $this->data_post;
//        ($params);

        return  BizproService::StandardPrice($params);
    }

    /**
     * [BizParams 查看商品的参数详情]
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月22日10:57:35
     */
    public function BizParams()
    {
        $params = $this->data_get;
        $where = [
            'b.id'=>$params['id']
        ];

        $data_params = [
            'where' => $where,
            'page' => false,
            'field' => 'params',
        ];
        $re = BizproService::BizproList($data_params);
        $data = empty($re['data'][0]) ? [] : $re['data'];
        return DataReturn('获取成功',0,$data);
    }
}